<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>nth-child demo</title>
    <style>
        ul {
            padding-left: 0;
            list-style-type: none;
            overflow: hidden;
        }
        ul > li {
            float: left;
            width: 30px;
            height: 30px;
            text-align: center;
            line-height: 30px;
            border: 1px solid #ccc;
            border-radius: 50%;
        }
        .demo01 li:nth-child(3) {
            color: #fff;
            background: blue;
        }
        .demo02 li:nth-child(2n) {
            color: #fff;
            background: blue;
        }  
        .demo03 li:nth-child(2n+1) {
            color: #fff;
            background: blue;
        } 
        .demo04 li:nth-child(3n+1) {
            color: #fff;
            background: blue;
        }                  
        /* 选中3+ */
        .demo05 li:nth-child(n+3){
            color: #fff;
            background: blue;
        }
        .demo06 li:nth-child(-n+3){
            color: #fff;
            background: blue;
        }
        .demo07 li:nth-child(2n+3){
            color: #fff;
            background: blue;
        }     
        /*  */
        .demo08 li:nth-last-child(3){
            color: #fff;
            background: red;            
        }
        .demo09 li:nth-last-child(-n+3){
            color: #fff;
            background: red;            
        }  
        .demo10 li:not(:nth-child(-n+3)):not(:nth-last-child(-n+3))  {
            color: #fff;
            background: green;
        }
    </style>
</head>
<body>
    <h1>nth-child demo</h1>
    <ul>
        <li>1</li>
        <li>2</li>
        <li>3</li>
        <li>4</li>
        <li>5</li>
        <li>6</li>
        <li>7</li>
        <li>8</li>
        <li>9</li>
        <li>10</li>
        <li>11</li>
        <li>12</li>
        <li>13</li>
        <li>14</li>
        <li>15</li>
        <li>16</li>
    </ul>
    <hr>
    <button data-class="demo01">nth-child(3)</button>
    <button data-class="demo02">nth-child(2n)</button>
    <button data-class="demo03">nth-child(2n+1)</button>
    <button data-class="demo04">nth-child(3n+1)</button>
    
    <button data-class="demo05">nth-child(n+3)</button>
    <button data-class="demo06">nth-child(-n+3)</button>
    <button data-class="demo07">nth-child(2n+3)</button>

    <button data-class="demo08">nth-last-child(3)</button>
    <button data-class="demo09">nth-last-child(-n+3)</button>

    <button data-class="demo10">:not(:nth-child(-n+3)):not(:nth-last-child(-n+3))</button>

    

    <script>
        var button = document.querySelectorAll('button')
        var target = document.querySelector('ul')
        button.forEach(item => {
            item.onclick = function() {
                target.className = this.dataset.class
            }
        })
    </script>
</body>
</html>